package com.maila.xiaoaoschool.activity;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.util.PrefUtil;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/12/6.
 */
public class SetPayPasswordActivity extends AppCompatActivity implements View.OnClickListener {


    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R.id.ll_title)
    AutoLinearLayout llTitle;
    @BindView(R.id.tv_zhanghao)
    TextView tvZhanghao;
    @BindView(R.id.values_tv)
    TextView valuesTv;
    @BindView(R.id.tv_yanzhengma)
    TextView tvYanzhengma;
    @BindView(R.id.send_verification_code)
    TextView sendVerificationCode;
    @BindView(R.id.vertical_view)
    View verticalView;
    @BindView(R.id.delete_captcha)
    ImageView deleteCaptcha;
    @BindView(R.id.enter_the_verification_code)
    EditText enterTheVerificationCode;
    @BindView(R.id.all_authentication)
    AutoLinearLayout allAuthentication;
    @BindView(R.id.btn_next)
    Button btnNext;
    private String userKey;
    private CountDownTimer timer;
    private String validate_type;
    private String mobile;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_up_to_pay_password);
        ButterKnife.bind(this);
        userKey = (String) PrefUtil.getStringPref(SetPayPasswordActivity.this, "key", "");

        btnNext.setOnClickListener(this);
        btnNext.setEnabled(false);

        enterTheVerificationCode.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (editable.length() > 0) {
                    deleteCaptcha.setVisibility(View.VISIBLE);
                    btnNext.setEnabled(true);
                    btnNext.setBackgroundResource(R.drawable.bg_rd_orange);
                } else {
                    deleteCaptcha.setVisibility(View.INVISIBLE);
                    btnNext.setEnabled(false);
                    btnNext.setBackgroundResource(R.drawable.bg_rd_gray);
                }
            }
        });
//        netValues.user_validate(userKey, new MyCallBack<String>() {
//            @Override
//            public void onSuccess(String result) {
//                super.onSuccess(result);
//                loadingDialog.dismiss();
//                final UserValidate userValidate = gson.fromJson(result, UserValidate.class);
//                switch (userValidate.getData().getValidate_type()) {
//                    case "email":
//                        validate_type = "email";
//                        tv_zhanghao.setText("已绑邮箱:");
//                        values_tv.setText(userValidate.getData().getBind_account());
//                        enter_the_verification_code.setHint("请输入验证码");
//                        send_verification_code.setOnClickListener(new View.OnClickListener() {
//                            @Override
//                            public void onClick(View view) {
//                                timer = new CountDownTimer(60000, 1000) {
//                                    @Override
//                                    public void onTick(long l) {
//                                        send_verification_code.setText("重新获取(" + (l / 1000) + ")");
//                                        send_verification_code.setEnabled(false);
//                                    }
//
//                                    @Override
//                                    public void onFinish() {
//                                        send_verification_code.setEnabled(true);
//                                        send_verification_code.setText("获取验证码");
//                                    }
//                                };
//                                timer.start();
//                                netValues.Send_email_code(userValidate.getData().getBind_account(), new MyCallBack<String>() {
//                                    @Override
//                                    public void onSuccess(String result) {
//                                        super.onSuccess(result);
//                                        CheckUserName checkUserName = gson.fromJson(result, CheckUserName.class);
//                                        Toast.makeText(SetPayPasswordActivity.this, checkUserName.getMessage(), Toast.LENGTH_SHORT).show();
//                                    }
//
//                                    @Override
//                                    public void onError(Throwable ex, boolean isOnCallback) {
//                                        super.onError(ex, isOnCallback);
//                                    }
//                                });
//                            }
//                        });

//                        break;
//                    case "mobile_phone":
//                        validate_type = "mobile_phone";
//                        tv_zhanghao.setText("已绑账号:");
//
//                        mobile = userValidate.getData().getBind_account().substring(0, 3) + "****" + userValidate.getData().getBind_account().substring(7, userValidate.getData().getBind_account().length());
//
//                        values_tv.setText(mobile);
//                        enter_the_verification_code.setHint("请输入短信验证码");
//                       send_verification_code.setOnClickListener(new View.OnClickListener() {
//                           @Override
//                           public void onClick(View view) {
//                               timer = new CountDownTimer(60000, 1000) {
//                                   @Override
//                                   public void onTick(long l) {
//                                       send_verification_code.setText("重新获取(" + (l / 1000) + ")");
//                                       send_verification_code.setEnabled(false);
//                                   }
//
//                                   @Override
//                                   public void onFinish() {
//                                       send_verification_code.setEnabled(true);
//                                       send_verification_code.setText("获取验证码");
//                                   }
//                               };
//                               timer.start();
//                               netValues.Send_mobile_code(userValidate.getData().getBind_account(), new MyCallBack<String>() {
//                                   @Override
//                                   public void onSuccess(String result) {
//                                       super.onSuccess(result);
//                                       CheckUserName checkUserName = gson.fromJson(result, CheckUserName.class);
//                                       Toast.makeText(SetPayPasswordActivity.this, checkUserName.getMessage(), Toast.LENGTH_SHORT).show();
//                                   }
//
//                                   @Override
//                                   public void onError(Throwable ex, boolean isOnCallback) {
//                                       super.onError(ex, isOnCallback);
//                                   }
//                               });
//                           }
//                       });
//
//                        break;
//                }
//            }
//
//            @Override
//            public void onError(Throwable ex, boolean isOnCallback) {
//                super.onError(ex, isOnCallback);
//                loadingDialog.dismiss();
//            }
//        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.white_return_iv:
                finish();
                break;
            case R.id.delete_captcha:
                enterTheVerificationCode.setText("");
                break;
            case R.id.btn_next:
//                netValues.Validate_user(validate_type, enter_the_verification_code.getText().toString(), new MyCallBack<String>() {
//                    @Override
//                    public void onSuccess(String result) {
//                        super.onSuccess(result);
//                        CheckUserName checkUserName = gson.fromJson(result, CheckUserName.class);
//                        if (checkUserName.getResult() == 1) {
//                            //跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳跳
//                            Intent intent = new Intent(SetPayPasswordActivity.this, NewPayPasswordActivity.class);
//                            startActivity(intent);
//                            finish();
//                        } else {
//                            Toast.makeText(SetPayPasswordActivity.this, checkUserName.getMessage(), Toast.LENGTH_SHORT).show();
//                        }
//                    }
//
//                    @Override
//                    public void onError(Throwable ex, boolean isOnCallback) {
//                        super.onError(ex, isOnCallback);
//                    }
//                });
                break;

        }
    }
}
